import 'dart:async';

import 'package:chathouse/pages/expert/projects_list.dart';
import 'package:chathouse/public/Config.dart';
import 'package:flutter/material.dart';

import '../../public/event_bus.dart';
import '../../util/base_utils.dart';
import '../../widgets/base_appbar.dart';
import '../../widgets/buttons_tabbar.dart';
import '../client/order/client_order_list.dart';
import 'expert_order_list.dart';

class ProjectsPage extends StatefulWidget {
  const ProjectsPage({Key? key}) : super(key: key);

  @override
  _ProjectsPageState createState() => _ProjectsPageState();
}

class _ProjectsPageState extends State<ProjectsPage> with AutomaticKeepAliveClientMixin,SingleTickerProviderStateMixin {

  @override
  bool get wantKeepAlive => true;
  late TabController tabController;
  StreamSubscription? refreshSubscription;

  int idx = 0;
  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this,initialIndex: 0);
  }

  void _handleTabSelection() {
    idx = tabController.index;
    print("idx ::::${idx}");
    if(idx == 0) {
      eventBus.fire(UpdateExpertProject(0));
    }
    if(idx == 1) {
      eventBus.fire(UpdateExpertProject(1));
    }
    if(idx == 2) {
      eventBus.fire(UpdateExpertProject(2));
    }
    setState(() {});
  }

  @override
  void dispose() {
    tabController.dispose();
    refreshSubscription?.cancel();
    super.dispose();
  }
  
  @override
  Widget build(BuildContext context) {
    // super.build(context);
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: getAppBar(leading: Container(), title: "我的項目"),
      body: Column(
        children: [
          Expanded(
              child: DefaultTabController(
            length: 3,
            child: Column(
              children: <Widget>[
                ButtonsTabBar(
                  controller: tabController,
                  duration: 0,
                  labelStyle: getTextStyle(16,
                      color: MyColors.red_2166474, fontType: FontType.BOLD),
                  unselectedLabelStyle: getTextStyle(16,
                      color: MyColors.black_0000011, fontType: FontType.BOLD),
                  contentPadding: EdgeInsets.symmetric(horizontal: 40.w),
                  buttonMargin:
                      EdgeInsets.only(bottom: 0, right: 5.w, top: 12.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(14.w),
                          topRight: Radius.circular(14.w))),
                  unselectedDecoration: BoxDecoration(
                      color: MyColors.gary_210210210,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(14.w),
                          topRight: Radius.circular(14.w))),
                  tabs: const [
                    Tab(
                      text: "全部",
                    ),
                    Tab(
                      text: "進行中",
                    ),
                    Tab(
                      text: "客戶評語",
                    ),
                  ],
                ).setContainer(
                    alignment: Alignment.center,
                    height: 45.w,
                    width: double.infinity,
                    color: MyColors.gary_232233237),
                Expanded(
                  child: TabBarView(
                    controller: tabController,
                    children: <Widget>[
                      ExpertOrderList(null,),
                      ExpertOrderList(1),
                      ExpertOrderList(2),
                    ],
                  ).setContainer(
                      margin: EdgeInsets.only(left: 16, right: 16, top: 6.w)),
                ),
              ],
            ),
          )),
        ],
      ),
    );
  }
}
